package com.texplose.controller;

import com.texplose.entity.User;
import com.texplose.entity.vo.ResponseResult;
import com.texplose.entity.vo.UserInfoVo;
import com.texplose.service.FileService;
import com.texplose.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author : cyj
 * @Timer : 2022/5/18
 * @Description :
 */

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;


    @PostMapping("/login")
    public ResponseResult login(@RequestBody User user) {
        return userService.wxLogin(user);
    }

    @GetMapping("/login")
    public ResponseResult getUserInfo(int id) {
        return userService.getUserInfo(id);
    }

    @GetMapping("/getUserById/{id}")
    public ResponseResult getUserById(@PathVariable("id") Integer id) {
        return userService.getUserById(id);
    }

    @PostMapping("/register")
    public ResponseResult register(@RequestBody User user) {
        return userService.wxRegister(user);
    }

    @PutMapping("/updatePassword")
    public ResponseResult updatePasswordByEmail(@RequestBody User user) {
        return userService.updatePasswordByEmail(user);
    }

    @PostMapping("/updateAvatarById")
    public ResponseResult updateAvatarById( Integer id, String avatarUrl){
        return userService.updateAvatarById(id,avatarUrl);
    }

    @PostMapping("/updateUserInfo")
    public ResponseResult updateUserInfo(@RequestBody UserInfoVo userInfo){
        return userService.updateUserInfo(userInfo);
    }

    @PutMapping("/resetPwd")
    public ResponseResult resetPwd(@RequestBody User user) {
        return userService.resetPwdByUserId(user);
    }

}
